#include "ViewEventWrapper.h"

#include <pybind11/functional.h>
#include <pybind11/pybind11.h>

#include <odv/odvCore/Viewer.h>
#include <odv/odvCore/ViewerEvent.h>

namespace py = pybind11;


#if 0 
// Bind the base ViewerEventHandler as a trampoline class
class PyViewerEventHandler : public odv::ViewerEventHandler {
public:
  using odv::ViewerEventHandler::ViewerEventHandler;

  void setViewer(odv::Viewer *viewer) override {
    PYBIND11_OVERRIDE_PURE(void, odv::ViewerEventHandler, setViewer, viewer);
  }

  odv::Viewer *getViewer() override {
    PYBIND11_OVERRIDE_PURE(odv::Viewer *, odv::ViewerEventHandler, getViewer);
  }

  // osgGA::GUIEventHandler* getOSGGUIEventHandler() override {
  //     PYBIND11_OVERRIDE_PURE(
  //         osgGA::GUIEventHandler*,
  //         odv::ViewerEventHandler,
  //         getOSGGUIEventHandler,
  //     );
  // }
};
#endif

void bind_ViewerEvent(py::module &m) {
  py::enum_<odv::EventType>(m, "EventType")
      .value("PUSH", odv::EventType::PUSH)
      .value("RELEASE", odv::EventType::RELEASE)
      .value("DOUBLECLICK", odv::EventType::DOUBLECLICK)
      .value("DRAG", odv::EventType::DRAG)
      .value("MOVE", odv::EventType::MOVE)
      .value("SCROLL", odv::EventType::SCROLL)
      .value("KEYDOWN", odv::EventType::KEYDOWN)
      .value("KEYUP", odv::EventType::KEYUP);

  py::enum_<odv::MouseButton>(m, "MouseButton")
      .value("LEFT_BUTTON", odv::MouseButton::LEFT_BUTTON)
      .value("MIDDLE_BUTTON", odv::MouseButton::MIDDLE_BUTTON)
      .value("RIGHT_BUTTON", odv::MouseButton::RIGHT_BUTTON)
      .value("None", odv::MouseButton::None);

#if 0 
  // 由于Viewer的传参是回调函数，所以此处不需要绑定ViewerEventHandler类
  // Forward declare Viewer class (assuming it's bound elsewhere)
  py::class_<odv::Viewer, std::shared_ptr<odv::Viewer>>(m, "Viewer");

  py::class_<odv::ViewerEventHandler, PyViewerEventHandler>(
      m, "ViewerEventHandler")
      .def(py::init<>())
      .def("setViewer", &odv::ViewerEventHandler::setViewer)
      .def("getViewer", &odv::ViewerEventHandler::getViewer);
  //.def("getOSGGUIEventHandler",&odv::ViewerEventHandler::getOSGGUIEventHandler);

  // Bind the callback types
  py::class_<odv::ViewerKeyEventCallback>(m, "ViewerKeyEventCallback");
  py::class_<odv::ViewerMouseButtonEventCallback>(m, "ViewerMouseButtonEventCallback");

  // Bind ViewerKeyboardHandler
  py::class_<odv::ViewerKeyboardHandler, odv::ViewerEventHandler>(
      m, "ViewerKeyboardHandler")
      .def(py::init<odv::Viewer *, odv::ViewerKeyEventCallback>(),
           py::arg("viewer"), py::arg("callback"))
      .def("setViewer", &odv::ViewerKeyboardHandler::setViewer)
      .def("getViewer", &odv::ViewerKeyboardHandler::getViewer);
  //.def("getOSGGUIEventHandler",&odv::ViewerKeyboardHandler::getOSGGUIEventHandler);

  // Bind ViewerMouseButtonHandler
  py::class_<odv::ViewerMouseButtonHandler, odv::ViewerEventHandler>(
      m, "ViewerMouseButtonHandler")
      .def(py::init<odv::Viewer *, odv::ViewerMouseButtonEventCallback>(),
           py::arg("viewer"), py::arg("callback"))
      .def("setViewer", &odv::ViewerMouseButtonHandler::setViewer)
      .def("getViewer", &odv::ViewerMouseButtonHandler::getViewer);
  //.def("getOSGGUIEventHandler",&odv::ViewerMouseButtonHandler::getOSGGUIEventHandler)
#endif

  ;
}